<?php

namespace App\Listeners;

use App\Events\LogArticleEvent;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Contracts\Queue\ShouldQueue;
use App\Repositories\Model\LogArticleRepository as LogArticle;

class LogArticleListener
{
    /**
     * LogArticleRepository
     *
     * @var LogArticle
     */
    protected $log;

    /**
     * LogArticleListener constructor.
     * @param LogArticle $log
     */
    public function __construct(LogArticle $log)
    {
        $this->log = $log;
    }

    /**
     * 将日志记录进mysql
     *
     * @param  LogArticleEvent  $event
     * @return void
     */
    public function handle(LogArticleEvent $event)
    {
        $data = [
            'ip' => $event->ip,
            'admin_id' => $event->admin_id,
            'now_data' => $event->now_data,
            'time' => $event->time,
            'title' => $event->title,
            'model_name' => $event->model_name,
            'change_field' => $event->change_field,
        ];
        $this->log->create($data);
    }
}
